package com.ys.timer;

import java.util.Date;
import java.util.List;

import com.ys.config.MyConfig;
import com.ys.mapper.business.DiySqlMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;

import com.bo.util.DateUtil;
import com.ys.entity.storage.TccStockControl;
import com.ys.enume.storage.TccStockSourceEnum;
import com.ys.service.storage.TccStockControlDailyService;
import com.ys.service.storage.TccStockControlService;

@Controller
public class TimerTccStockControlDaily {

    @Autowired
    private TccStockControlService tccStockControlService;
    @Autowired
    private TccStockControlDailyService tccStockControlDailyService;


	@Autowired
	private DiySqlMapper diySqlMapper;

	@Scheduled(cron = "0 10 0 * * * ")
	public void updateTccStockControlDaily() {
		
		String day = DateUtil.getYYYY_MM_DD(DateUtil.addDays(new Date(), -1));
		
		// 添加每日数据
		tccStockControlDailyService.addBatch(day);
	}

	@Scheduled(cron = "0 15 0 * * * ")
	public void updateTccStock() {
		
		String dayAgo = DateUtil.getYYYY_MM_DD(DateUtil.addDays(new Date(), -30));
		List<TccStockControl> listTccStockControl = new TccStockControl()
				.setIsParent(TccStockSourceEnum.IsParent.NO.value)
				.where("A.ProductNum > 0")
				.where("A.ProductNumAll > 0")
				.where("A.DRkSj <= '" + dayAgo + "'")
				.queryList();
		for(TccStockControl tccStockControl : listTccStockControl) {
			tccStockControlService.stockOutSub(tccStockControl.getGuid(), dayAgo);
		}
	}

	@Scheduled(cron = "* 2 * * * ?")
	public void synchronizationChw() throws Exception{
		if ("pro".equals(MyConfig.getActive())) {
			//每分钟同步1.0和1.5货位信息
			diySqlMapper.synchronizationChw();
		}
	}
	
}
